{% extends "base.html" %}

{% block content %}
<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h4 class="mb-0">论文详情</h4>
                </div>
                <div class="card-body">
                    <h5 class="card-title">{{ thesis.title }}</h5>
                    <p class="card-text">{{ thesis.description }}</p>
                    <ul class="list-group list-group-flush">
                        <li class="list-group-item">
                            <strong>编程语言：</strong> {{ thesis.programming_language }}
                        </li>
                        <li class="list-group-item">
                            <strong>预算：</strong> 
                            ¥{{ "%.2f"|format(thesis.price) }}
                            {% if thesis.need_environment %}
                            <small class="text-muted">（含环境配置费用100元）</small>
                            {% endif %}
                        </li>
                        <li class="list-group-item">
                            <strong>状态：</strong> 
                            {% if thesis.status == 'pending' %}
                                <span class="badge bg-warning">待处理</span>
                            {% elif thesis.status == 'accepted' %}
                                <span class="badge bg-info">已接受</span>
                            {% elif thesis.status == 'completed' %}
                                <span class="badge bg-success">已完成</span>
                            {% endif %}
                        </li>
                        <li class="list-group-item">
                            <strong>联系方式：</strong> {{ thesis.contact_info }}
                        </li>
                        <li class="list-group-item">
                            <strong>期望完成日期：</strong> {{ thesis.deadline.strftime('%Y-%m-%d') }}
                        </li>
                        <li class="list-group-item">
                            <strong>需要环境配置：</strong> 
                            {% if thesis.need_environment %}
                                <span class="badge bg-success">是</span>
                            {% else %}
                                <span class="badge bg-secondary">否</span>
                            {% endif %}
                        </li>
                        <li class="list-group-item">
                            <strong>提交时间：</strong> {{ thesis.created_at.strftime('%Y-%m-%d %H:%M:%S') }}
                        </li>
                        {% if thesis.proposal_file %}
                        <li class="list-group-item">
                            <strong>开题报告：</strong>
                            <a href="{{ url_for('main.download_proposal', filename=thesis.proposal_file) }}" class="btn btn-sm btn-primary">
                                <i class="fas fa-download"></i> 下载开题报告
                            </a>
                        </li>
                        {% else %}
                        <li class="list-group-item">
                            <strong>开题报告：</strong>
                            <span class="text-muted">暂未上传</span>
                            {% if current_user.id == thesis.user_id %}
                            <small class="d-block mt-1">
                                您可以通过编辑论文信息来上传开题报告
                            </small>
                            {% endif %}
                        </li>
                        {% endif %}
                    </ul>
                </div>
                {% if current_user.id == thesis.user_id %}
                <div class="card-footer">
                    <div class="d-flex justify-content-between">
                        <a href="{{ url_for('main.edit_thesis', id=thesis.id) }}" class="btn btn-warning">编辑</a>
                        <button type="button" class="btn btn-danger" onclick="deleteThesis({{ thesis.id }})">删除</button>
                    </div>
                </div>
                {% endif %}
            </div>
            <div class="mt-3">
                {% if source == 'admin' %}
                    <a href="{{ url_for('admin.theses') }}" class="btn btn-secondary">返回列表</a>
                {% else %}
                    <a href="{{ url_for('main.my_theses') }}" class="btn btn-secondary">返回列表</a>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<!-- 删除确认模态框 -->
<div class="modal fade" id="deleteModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">确认删除</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                确定要删除这个论文吗？
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <form action="{{ url_for('main.delete_thesis', id=thesis.id) }}" method="POST" class="d-inline">
                    <button type="submit" class="btn btn-danger">确定删除</button>
                </form>
            </div>
        </div>
    </div>
</div>

{% block scripts %}
<script>
function deleteThesis(id) {
    new bootstrap.Modal(document.getElementById('deleteModal')).show();
}
</script>
{% endblock %}

{% endblock %} 